package com.trkj.controller.lzs;


import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojo.Salary;
import com.trkj.pojo.SalaryAccount;

import com.trkj.service.lzs.Salaryservice;
import com.trkj.vo.Result;
import com.trkj.vo.Result2;
import com.trkj.vo.payVO;

@Controller
public class SalaryAccountController {
	//查询所有
   @Autowired
   private  Salaryservice Salaryservice;
  /* @Autowired
   private RecruitprocessService  Recruitprocess;*/
	@RequestMapping("to_a")
	public String cen() {
		return "salaryaccount";
      }
	@RequestMapping("lzs_findAllSalary")
	@ResponseBody
	public List<SalaryAccount> getJSON2(){
		List<SalaryAccount> list = Salaryservice.SalaryAccount1();
		
		return list;
	}
	//查询shuoy\
	
	//模糊查询shuoy
	@RequestMapping("lzs_findallchaxun")
	@ResponseBody
	public  List<SalaryAccount> Query(String text){
		System.out.println(text);
		return (List<SalaryAccount>) Salaryservice.queryByName(text);
	}
	
/*	@RequestMapping("lzs_findallchaxun")
	@ResponseBody
	public  List<SalaryAccount> Query(String key){
		
		Salaryservice.queryByName(key).forEach(e->{
		
		});
		return Salaryservice.queryByName(key);
	}*/
	//分页
	@RequestMapping("lzs-fenye")
	@ResponseBody  
	public  Map  SalaryAccountpage(int page, int rows) {
		Long total=Salaryservice.SalaryAccountByPageCount();	
		List <SalaryAccount>list = Salaryservice.fenye(page, rows);
		Map  map=new HashMap<>();
		map.put("total",total);
		map.put("rows", list);
		
		return map;
		
	}
//编辑
	@RequestMapping("lzs-bianji")
	@ResponseBody  
	public   SalaryAccount bianji(Long accountId) {
		/*Long total=Salaryservice.SalaryAccountByPageCount();	*/
		System.out.println("accountIdaccountId"+accountId);
		return  Salaryservice.chun(accountId);
		
	}
	/*修改
	*/
	@RequestMapping("lzs_xiugai")
	@ResponseBody  
	public  Result2  xiugai( Long accountId,String accountName,BigDecimal accountNumber,String accountPerson,
			String accountRemark,Timestamp accountStartdate,Timestamp accountEnddate) {
		try {
			Salaryservice.lzs_Edit(accountId,accountName, accountNumber, accountPerson, accountRemark, accountStartdate,accountEnddate,new Timestamp(new Date().getTime()));
			return Result2.SUCCESS;
		} catch (Exception e) {
				e.printStackTrace();
			return Result2.failure(e.getMessage());
		}
		
	}
	//多表查询
	@RequestMapping("lzs_findAllduoSalary")
	@ResponseBody
	public List<payVO> duobiao(){
  
		
		return 	 Salaryservice.selcet_SalaryAccount();
	}
	//多表增加
	@RequestMapping("pay_add")
	@ResponseBody
	public Result add_SalaryAccount(SalaryAccount s,Long templateId){
	s.setAccountCreatordate(new Timestamp(new Date().getTime()));
	try {
		System.err.println(templateId);
		Salaryservice.add_SalaryAccount(s, templateId);
	return Result.SUCCESS;
	} catch (Exception e) {
	e.printStackTrace();
	return Result.failure(e.getMessage());
	}
	}
	//删除；通过id查出相应的一条数据
			@RequestMapping("hr_ra_form_SalaryAccount")
			@ResponseBody
			public boolean hr_ra_form_dlt(Long accountId){
				 return Salaryservice.dltRa(accountId);
			}
					
}
